#include <REGX52.H>

void Delay(unsigned int x) {
    unsigned char i,j;
    while(x--) {
        i=2;
        j=199;
        do {
            while(j--);
        } while(i--);
    }
}

void main() {
	unsigned char tmp=0;
	P2=~0x01;
    while(1) {
			if(P3_1==0){
				Delay(20);
				while(P3_1==0);
				Delay(20);
				
				tmp++;
				if(tmp>=8)
					tmp=0;
				P2=~(0x01<<tmp);
			}
			if(P3_0==0){
				Delay(20);
				while(P3_1==0);
				Delay(20);
				
				if(tmp==0)
					tmp=7;
				else
					tmp--;
				P2=~(0x01<<tmp);
			}
    }
}